
package com.yuan.servlet;

import com.yuan.hibernate.Users;
import com.yuan.hibernate.UsersDAO;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class loginservlet extends BaseHttpServlet {
    private UsersDAO mUsersDAO = null;
    private Users mUsers = null;
    private List<?> list = null;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        super.doGet(request, response);
        mUsersDAO = new UsersDAO();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if (username == null || username.length() < 1 || password == null || password.length() < 1)
        {
            mResponse = "输入错误";
        }
        else {
            mUsers = new Users();
            mUsers.setPwd(password);
            mUsers.setUsername(username);
            list = mUsersDAO.findByExample(mUsers);
            if (list.size() != 1)
            {
                mResponse = "登录失败";
            } else
            {
                mResponse = com.yuan.util.JsonUtils.getFromList(list);
            }
        }
        closeAndClear();
    }

    protected synchronized void closeAndClear() {
        mUsersDAO = null;
        mUsers = null;
        list = null;
        super.closeAndClear();

    }
}
